<template>
    <view class="container b-f">
        <!-- DIY组件 -->

        <diy-component :diyItems="items"></diy-component>

        <!-- 底线 -->
        <!-- <view class="title-footer p-r">
    <text class="f-24 col-9 cont">我是有底线的</text>
    <view class="hr"></view>
  </view> -->
    </view>
</template>

<script>
import diyComponent from '@/pages/diy/index';
const app = getApp();
export default {
    components: {
        diyComponent
    },
    data() {
        return {
            // 页面元素
            items: {},
            scrollTop: 0
        };
    },
    onShow: function (options) {
        // 获取小程序基础信息
        let appInfo = uni.getStorageSync('app');
        console.log(appInfo);
        if (!appInfo) {
            app.globalData.getAppBase();
        }
        let token = uni.getStorageSync('token');
        if (!token) {
            app.globalData.doLogin();
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        /*let roomId = 1
  let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 }))
  wx.navigateTo({
      url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
  })*/

        // 加载页面数据
        this.getPageData();
    },
    /**
     * 分享当前页面
     */
    onShareAppMessage: function () {
        let params = this.items.page.params;
        return {
            title: params.share_title,
            path: '/pages/index/index?referee_id=' + app.globalData.getUserId()
        };
    },
    /**
     * 下拉刷新
     */
    // /**
    //  * 返回顶部
    //  */
    // goTop: function(t) {
    //   this.setData({
    //     scrollTop: 0
    //   });
    // },
    // scroll: function(t) {
    //   this.setData({
    //     indexSearch: t.detail.scrollTop
    //   }), t.detail.scrollTop > 300 ? this.setData({
    //     floorstatus: !0
    //   }) : this.setData({
    //     floorstatus: !1
    //   });
    // },
    onPullDownRefresh: function () {
        // 获取首页数据
        this.getPageData(function () {
            uni.stopPullDownRefresh();
        });
    },
    methods: {
        /**
         * 加载页面数据
         */
        getPageData: function (callback) {
            let that = this;
            app.globalData._get('page/home', {}, function (result) {
                // 设置顶部导航栏栏
                that.setPageBar(result.data.items.page);
                //wx.setStorageSync('titleBackgroundColor', result.data.items.page.style.titleBackgroundColor);
                //console.log('hdo',result.data)
                that.setData(result.data);
                // 回调函数
                if (typeof callback === 'function') {
                    callback();
                }
            });
        },

        /**
         * 设置顶部导航栏
         */
        setPageBar: function (page) {
            // 设置页面标题
            uni.setNavigationBarTitle({
                title: page.params.title
            });
            // 设置navbar标题、颜色
            uni.setNavigationBarColor({
                frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
                backgroundColor: page.style.titleBackgroundColor
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
